# coding:utf8

from typing import List
import numpy as np

def cosine_sim(vector1: List[float], vector2: List[float]) -> float:
    """
    计算两个向量之间的余弦相似度
    """
    dot_product = np.dot(vector1, vector2)
    magnitude = np.linalg.norm(vector1) * np.linalg.norm(vector2)
    if not magnitude:
        return 0
    return dot_product / magnitude

# test embeding consine
from embedding import embedding
text1 = '我喜欢吃苹果'
text2 = "苹果是我最喜欢吃的水果"
text3 = "我喜欢用苹果手机"

v1 = embedding(text1)
v2 = embedding(text2)
v3 = embedding(text3)

cos12 = cosine_sim(v1, v2)
print(cos12)

cos13 = cosine_sim(v1, v3)
print(cos13)

cos23 = cosine_sim(v2, v3)
print(cos23)